﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.LinQuick;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;
using TaleWorlds.SaveSystem.Load;

namespace TaleWorlds.CampaignSystem
{
	// Token: 0x02000056 RID: 86
	public sealed class CharacterObject : BasicCharacterObject, ICharacterData
	{
		// Token: 0x0600091A RID: 2330 RVA: 0x00037E96 File Offset: 0x00036096
		internal static void AutoGeneratedStaticCollectObjectsCharacterObject(object o, List<object> collectedObjects)
		{
			((CharacterObject)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x0600091B RID: 2331 RVA: 0x00037EA4 File Offset: 0x000360A4
		protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			collectedObjects.Add(this._heroObject);
			collectedObjects.Add(this._originCharacter);
		}

		// Token: 0x0600091C RID: 2332 RVA: 0x00037EC5 File Offset: 0x000360C5
		internal static object AutoGeneratedGetMemberValue_heroObject(object o)
		{
			return ((CharacterObject)o)._heroObject;
		}

		// Token: 0x0600091D RID: 2333 RVA: 0x00037ED2 File Offset: 0x000360D2
		internal static object AutoGeneratedGetMemberValue_originCharacter(object o)
		{
			return ((CharacterObject)o)._originCharacter;
		}

		// Token: 0x170001C0 RID: 448
		// (get) Token: 0x0600091E RID: 2334 RVA: 0x00037EDF File Offset: 0x000360DF
		public override TextObject Name
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.Name;
				}
				return base.Name;
			}
		}

		// Token: 0x170001C1 RID: 449
		// (get) Token: 0x0600091F RID: 2335 RVA: 0x00037EFB File Offset: 0x000360FB
		public string EncyclopediaLink
		{
			get
			{
				if (!this.IsHero)
				{
					return Campaign.Current.EncyclopediaManager.GetIdentifier(typeof(CharacterObject)) + "-" + base.StringId;
				}
				return this._heroObject.EncyclopediaLink;
			}
		}

		// Token: 0x170001C2 RID: 450
		// (get) Token: 0x06000920 RID: 2336 RVA: 0x00037F3C File Offset: 0x0003613C
		public TextObject EncyclopediaLinkWithName
		{
			get
			{
				if (this.IsHero)
				{
					return this._heroObject.EncyclopediaLinkWithName;
				}
				if (Campaign.Current.EncyclopediaManager.GetPageOf(typeof(CharacterObject)).IsValidEncyclopediaItem(this))
				{
					return HyperlinkTexts.GetUnitHyperlinkText(this.EncyclopediaLink, this.Name);
				}
				return this.Name;
			}
		}

		// Token: 0x170001C3 RID: 451
		// (get) Token: 0x06000921 RID: 2337 RVA: 0x00037F96 File Offset: 0x00036196
		// (set) Token: 0x06000922 RID: 2338 RVA: 0x00037F9E File Offset: 0x0003619E
		public bool HiddenInEncylopedia { get; set; }

		// Token: 0x06000923 RID: 2339 RVA: 0x00037FA7 File Offset: 0x000361A7
		public override string ToString()
		{
			return this.Name.ToString();
		}

		// Token: 0x170001C4 RID: 452
		// (get) Token: 0x06000924 RID: 2340 RVA: 0x00037FB4 File Offset: 0x000361B4
		public bool IsNotTransferableInPartyScreen
		{
			get
			{
				return (this._characterRestrictionFlags & CharacterRestrictionFlags.NotTransferableInPartyScreen) == CharacterRestrictionFlags.NotTransferableInPartyScreen;
			}
		}

		// Token: 0x170001C5 RID: 453
		// (get) Token: 0x06000925 RID: 2341 RVA: 0x00037FC1 File Offset: 0x000361C1
		public bool IsNotTransferableInHideouts
		{
			get
			{
				return (this._characterRestrictionFlags & CharacterRestrictionFlags.CanNotGoInHideout) == CharacterRestrictionFlags.CanNotGoInHideout;
			}
		}

		// Token: 0x170001C6 RID: 454
		// (get) Token: 0x06000926 RID: 2342 RVA: 0x00037FCE File Offset: 0x000361CE
		public CharacterObject OriginalCharacter
		{
			get
			{
				return this._originCharacter;
			}
		}

		// Token: 0x170001C7 RID: 455
		// (get) Token: 0x06000927 RID: 2343 RVA: 0x00037FD6 File Offset: 0x000361D6
		public bool IsOriginalCharacter
		{
			get
			{
				return this._originCharacter == null;
			}
		}

		// Token: 0x170001C8 RID: 456
		// (get) Token: 0x06000928 RID: 2344 RVA: 0x00037FE1 File Offset: 0x000361E1
		// (set) Token: 0x06000929 RID: 2345 RVA: 0x00037FE9 File Offset: 0x000361E9
		public Hero HeroObject
		{
			get
			{
				return this._heroObject;
			}
			internal set
			{
				this._heroObject = value;
			}
		}

		// Token: 0x170001C9 RID: 457
		// (get) Token: 0x0600092A RID: 2346 RVA: 0x00037FF2 File Offset: 0x000361F2
		public override MBReadOnlyList<Equipment> AllEquipments
		{
			get
			{
				if (!this.IsHero)
				{
					return base.AllEquipments;
				}
				return new MBList<Equipment>
				{
					this.HeroObject.BattleEquipment,
					this.HeroObject.CivilianEquipment
				};
			}
		}

		// Token: 0x170001CA RID: 458
		// (get) Token: 0x0600092B RID: 2347 RVA: 0x0003802A File Offset: 0x0003622A
		public override Equipment Equipment
		{
			get
			{
				if (!this.IsHero)
				{
					return base.Equipment;
				}
				return this.HeroObject.BattleEquipment;
			}
		}

		// Token: 0x170001CB RID: 459
		// (get) Token: 0x0600092C RID: 2348 RVA: 0x00038048 File Offset: 0x00036248
		public IEnumerable<Equipment> BattleEquipments
		{
			get
			{
				if (!this.IsHero)
				{
					return this.AllEquipments.WhereQ((Equipment e) => !e.IsCivilian);
				}
				return new List<Equipment>
				{
					this.HeroObject.BattleEquipment
				}.AsEnumerable<Equipment>();
			}
		}

		// Token: 0x170001CC RID: 460
		// (get) Token: 0x0600092D RID: 2349 RVA: 0x000380A4 File Offset: 0x000362A4
		public IEnumerable<Equipment> CivilianEquipments
		{
			get
			{
				if (this.IsHero)
				{
					return new List<Equipment>
					{
						this.HeroObject.CivilianEquipment
					}.AsEnumerable<Equipment>();
				}
				return this.AllEquipments.WhereQ((Equipment e) => e.IsCivilian);
			}
		}

		// Token: 0x170001CD RID: 461
		// (get) Token: 0x0600092E RID: 2350 RVA: 0x000380FF File Offset: 0x000362FF
		public Equipment FirstBattleEquipment
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.BattleEquipment;
				}
				return this.AllEquipments.FirstOrDefaultQ((Equipment e) => !e.IsCivilian);
			}
		}

		// Token: 0x170001CE RID: 462
		// (get) Token: 0x0600092F RID: 2351 RVA: 0x0003813F File Offset: 0x0003633F
		public Equipment FirstCivilianEquipment
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.CivilianEquipment;
				}
				return this.AllEquipments.FirstOrDefaultQ((Equipment e) => e.IsCivilian);
			}
		}

		// Token: 0x170001CF RID: 463
		// (get) Token: 0x06000930 RID: 2352 RVA: 0x0003817F File Offset: 0x0003637F
		public Equipment RandomBattleEquipment
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.BattleEquipment;
				}
				return this.AllEquipments.GetRandomElementWithPredicate((Equipment e) => !e.IsCivilian);
			}
		}

		// Token: 0x170001D0 RID: 464
		// (get) Token: 0x06000931 RID: 2353 RVA: 0x000381BF File Offset: 0x000363BF
		public Equipment RandomCivilianEquipment
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.CivilianEquipment;
				}
				return this.AllEquipments.GetRandomElementWithPredicate((Equipment e) => e.IsCivilian);
			}
		}

		// Token: 0x170001D1 RID: 465
		// (get) Token: 0x06000932 RID: 2354 RVA: 0x000381FF File Offset: 0x000363FF
		public override int HitPoints
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.HitPoints;
				}
				return this.MaxHitPoints();
			}
		}

		// Token: 0x170001D2 RID: 466
		// (get) Token: 0x06000933 RID: 2355 RVA: 0x0003821B File Offset: 0x0003641B
		public override string HairTags
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.HairTags;
				}
				return base.HairTags;
			}
		}

		// Token: 0x170001D3 RID: 467
		// (get) Token: 0x06000934 RID: 2356 RVA: 0x00038237 File Offset: 0x00036437
		public override string BeardTags
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.BeardTags;
				}
				return base.BeardTags;
			}
		}

		// Token: 0x170001D4 RID: 468
		// (get) Token: 0x06000935 RID: 2357 RVA: 0x00038253 File Offset: 0x00036453
		public override string TattooTags
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.TattooTags;
				}
				return base.TattooTags;
			}
		}

		// Token: 0x06000936 RID: 2358 RVA: 0x00038270 File Offset: 0x00036470
		public override int MaxHitPoints()
		{
			return MathF.Round(Campaign.Current.Models.CharacterStatsModel.MaxHitpoints(this, false).ResultNumber);
		}

		// Token: 0x170001D5 RID: 469
		// (get) Token: 0x06000937 RID: 2359 RVA: 0x000382A0 File Offset: 0x000364A0
		public ExplainedNumber MaxHitPointsExplanation
		{
			get
			{
				return Campaign.Current.Models.CharacterStatsModel.MaxHitpoints(this, true);
			}
		}

		// Token: 0x170001D6 RID: 470
		// (get) Token: 0x06000938 RID: 2360 RVA: 0x000382B8 File Offset: 0x000364B8
		public override int Level
		{
			get
			{
				if (!this.IsHero)
				{
					return base.Level;
				}
				return this.HeroObject.Level;
			}
		}

		// Token: 0x06000939 RID: 2361 RVA: 0x000382D4 File Offset: 0x000364D4
		public CharacterObject()
		{
			this.Init();
		}

		// Token: 0x0600093A RID: 2362 RVA: 0x000382EE File Offset: 0x000364EE
		[LoadInitializationCallback]
		private void OnLoad(MetaData metaData, ObjectLoadData objectLoadData)
		{
			this.Init();
		}

		// Token: 0x0600093B RID: 2363 RVA: 0x000382F6 File Offset: 0x000364F6
		private void Init()
		{
			this._occupation = Occupation.NotAssigned;
			this._characterTraits = new CharacterTraits();
			this.Level = 1;
			this._characterRestrictionFlags = CharacterRestrictionFlags.None;
		}

		// Token: 0x0600093C RID: 2364 RVA: 0x00038318 File Offset: 0x00036518
		public static CharacterObject CreateFrom(CharacterObject character)
		{
			CharacterObject characterObject = MBObjectManager.Instance.CreateObject<CharacterObject>();
			characterObject._originCharacter = (character._originCharacter ?? character);
			if (characterObject.IsHero)
			{
				characterObject.HeroObject.StaticBodyProperties = (character.IsHero ? character.HeroObject.StaticBodyProperties : character.GetBodyPropertiesMin(false).StaticProperties);
			}
			characterObject._occupation = character._occupation;
			characterObject._persona = character._persona;
			characterObject._characterTraits = new CharacterTraits(character._characterTraits);
			characterObject._civilianEquipmentTemplate = character._civilianEquipmentTemplate;
			characterObject._battleEquipmentTemplate = character._battleEquipmentTemplate;
			characterObject.FillFrom(character);
			return characterObject;
		}

		// Token: 0x170001D7 RID: 471
		// (get) Token: 0x0600093D RID: 2365 RVA: 0x000383C1 File Offset: 0x000365C1
		public static CharacterObject PlayerCharacter
		{
			get
			{
				return Game.Current.PlayerTroop as CharacterObject;
			}
		}

		// Token: 0x170001D8 RID: 472
		// (get) Token: 0x0600093E RID: 2366 RVA: 0x000383D2 File Offset: 0x000365D2
		public static CharacterObject OneToOneConversationCharacter
		{
			get
			{
				return Campaign.Current.ConversationManager.OneToOneConversationCharacter;
			}
		}

		// Token: 0x170001D9 RID: 473
		// (get) Token: 0x0600093F RID: 2367 RVA: 0x000383E3 File Offset: 0x000365E3
		public static IEnumerable<CharacterObject> ConversationCharacters
		{
			get
			{
				return Campaign.Current.ConversationManager.ConversationCharacters;
			}
		}

		// Token: 0x06000940 RID: 2368 RVA: 0x000383F4 File Offset: 0x000365F4
		public override void AfterRegister()
		{
			base.AfterRegister();
			if (this.Equipment != null)
			{
				this.Equipment.SyncEquipments = true;
			}
			if (this.FirstCivilianEquipment != null)
			{
				this.FirstCivilianEquipment.SyncEquipments = true;
			}
		}

		// Token: 0x170001DA RID: 474
		// (get) Token: 0x06000941 RID: 2369 RVA: 0x00038424 File Offset: 0x00036624
		// (set) Token: 0x06000942 RID: 2370 RVA: 0x00038445 File Offset: 0x00036645
		public new CultureObject Culture
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.Culture;
				}
				return (CultureObject)base.Culture;
			}
			set
			{
				if (this.IsHero)
				{
					this.HeroObject.Culture = value;
					return;
				}
				base.Culture = value;
			}
		}

		// Token: 0x06000943 RID: 2371 RVA: 0x00038463 File Offset: 0x00036663
		public override BodyProperties GetBodyPropertiesMin(bool returnBaseValue = false)
		{
			if (this.IsHero && !returnBaseValue)
			{
				return this.HeroObject.BodyProperties;
			}
			return base.GetBodyPropertiesMin(false);
		}

		// Token: 0x06000944 RID: 2372 RVA: 0x00038483 File Offset: 0x00036683
		public override BodyProperties GetBodyPropertiesMax()
		{
			if (this.IsHero)
			{
				return this.HeroObject.BodyProperties;
			}
			return base.GetBodyPropertiesMax();
		}

		// Token: 0x170001DB RID: 475
		// (get) Token: 0x06000945 RID: 2373 RVA: 0x0003849F File Offset: 0x0003669F
		public override bool IsFemale
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.IsFemale;
				}
				return base.IsFemale;
			}
		}

		// Token: 0x06000946 RID: 2374 RVA: 0x000384BC File Offset: 0x000366BC
		public override void UpdatePlayerCharacterBodyProperties(BodyProperties properties, int race, bool isFemale)
		{
			if (this.IsPlayerCharacter && this.IsHero)
			{
				this.HeroObject.StaticBodyProperties = properties.StaticProperties;
				this.HeroObject.Weight = properties.Weight;
				this.HeroObject.Build = properties.Build;
				base.Race = race;
				this.HeroObject.UpdatePlayerGender(isFemale);
				CampaignEventDispatcher.Instance.OnPlayerBodyPropertiesChanged();
			}
		}

		// Token: 0x170001DC RID: 476
		// (get) Token: 0x06000947 RID: 2375 RVA: 0x0003852C File Offset: 0x0003672C
		// (set) Token: 0x06000948 RID: 2376 RVA: 0x00038534 File Offset: 0x00036734
		public bool IsBasicTroop { get; set; }

		// Token: 0x170001DD RID: 477
		// (get) Token: 0x06000949 RID: 2377 RVA: 0x0003853D File Offset: 0x0003673D
		// (set) Token: 0x0600094A RID: 2378 RVA: 0x00038545 File Offset: 0x00036745
		public bool IsTemplate { get; private set; }

		// Token: 0x170001DE RID: 478
		// (get) Token: 0x0600094B RID: 2379 RVA: 0x0003854E File Offset: 0x0003674E
		// (set) Token: 0x0600094C RID: 2380 RVA: 0x00038556 File Offset: 0x00036756
		public bool IsChildTemplate { get; private set; }

		// Token: 0x170001DF RID: 479
		// (get) Token: 0x0600094D RID: 2381 RVA: 0x0003855F File Offset: 0x0003675F
		public override bool IsPlayerCharacter
		{
			get
			{
				return CharacterObject.PlayerCharacter == this;
			}
		}

		// Token: 0x170001E0 RID: 480
		// (get) Token: 0x0600094E RID: 2382 RVA: 0x00038569 File Offset: 0x00036769
		public override bool IsHero
		{
			get
			{
				return this._heroObject != null;
			}
		}

		// Token: 0x170001E1 RID: 481
		// (get) Token: 0x0600094F RID: 2383 RVA: 0x00038574 File Offset: 0x00036774
		public bool IsRegular
		{
			get
			{
				return this._heroObject == null;
			}
		}

		// Token: 0x170001E2 RID: 482
		// (get) Token: 0x06000950 RID: 2384 RVA: 0x0003857F File Offset: 0x0003677F
		public Occupation Occupation
		{
			get
			{
				if (this.IsHero)
				{
					return this.HeroObject.Occupation;
				}
				return this._occupation;
			}
		}

		// Token: 0x06000951 RID: 2385 RVA: 0x0003859B File Offset: 0x0003679B
		public Occupation GetDefaultOccupation()
		{
			return this._occupation;
		}

		// Token: 0x170001E3 RID: 483
		// (get) Token: 0x06000952 RID: 2386 RVA: 0x000385A3 File Offset: 0x000367A3
		public override float Age
		{
			get
			{
				Hero heroObject = this.HeroObject;
				if (heroObject == null)
				{
					return base.Age;
				}
				return heroObject.Age;
			}
		}

		// Token: 0x170001E4 RID: 484
		// (get) Token: 0x06000953 RID: 2387 RVA: 0x000385BB File Offset: 0x000367BB
		public int ConformityNeededToRecruitPrisoner
		{
			get
			{
				return Campaign.Current.Models.PrisonerRecruitmentCalculationModel.GetConformityNeededToRecruitPrisoner(this);
			}
		}

		// Token: 0x170001E5 RID: 485
		// (get) Token: 0x06000954 RID: 2388 RVA: 0x000385D2 File Offset: 0x000367D2
		// (set) Token: 0x06000955 RID: 2389 RVA: 0x000385DA File Offset: 0x000367DA
		public CharacterObject[] UpgradeTargets { get; private set; } = new CharacterObject[0];

		// Token: 0x170001E6 RID: 486
		// (get) Token: 0x06000956 RID: 2390 RVA: 0x000385E3 File Offset: 0x000367E3
		// (set) Token: 0x06000957 RID: 2391 RVA: 0x000385EB File Offset: 0x000367EB
		public ItemCategory UpgradeRequiresItemFromCategory { get; private set; }

		// Token: 0x06000958 RID: 2392 RVA: 0x000385F4 File Offset: 0x000367F4
		public bool HasThrowingWeapon()
		{
			for (EquipmentIndex equipmentIndex = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex < EquipmentIndex.NumAllWeaponSlots; equipmentIndex++)
			{
				ItemObject item = this.Equipment[equipmentIndex].Item;
				if (item != null && item.Type == ItemObject.ItemTypeEnum.Thrown)
				{
					return true;
				}
			}
			return false;
		}

		// Token: 0x06000959 RID: 2393 RVA: 0x00038634 File Offset: 0x00036834
		public int GetUpgradeXpCost(PartyBase party, int index)
		{
			CharacterObject upgradeTarget = null;
			if (index >= 0 && index < this.UpgradeTargets.Length)
			{
				upgradeTarget = this.UpgradeTargets[index];
			}
			return Campaign.Current.Models.PartyTroopUpgradeModel.GetXpCostForUpgrade(party, this, upgradeTarget);
		}

		// Token: 0x0600095A RID: 2394 RVA: 0x00038672 File Offset: 0x00036872
		public int GetUpgradeGoldCost(PartyBase party, int index)
		{
			return Campaign.Current.Models.PartyTroopUpgradeModel.GetGoldCostForUpgrade(party, this, this.UpgradeTargets[index]);
		}

		// Token: 0x0600095B RID: 2395 RVA: 0x00038694 File Offset: 0x00036894
		public void InitializeHeroCharacterOnAfterLoad()
		{
			base.InitializeHeroBasicCharacterOnAfterLoad(this._originCharacter);
			this._occupation = this._originCharacter._occupation;
			this.IsChildTemplate = this._originCharacter.IsChildTemplate;
			this._basicName = this._originCharacter._basicName;
			this.UpgradeTargets = this._originCharacter.UpgradeTargets;
			this.IsBasicTroop = this._originCharacter.IsBasicTroop;
			this.UpgradeRequiresItemFromCategory = this._originCharacter.UpgradeRequiresItemFromCategory;
			this._civilianEquipmentTemplate = this._originCharacter._civilianEquipmentTemplate;
			this._battleEquipmentTemplate = this._originCharacter._battleEquipmentTemplate;
			this._persona = this._originCharacter._persona;
			this._characterTraits = this._originCharacter._characterTraits;
			this.DefaultCharacterSkills = this._originCharacter.DefaultCharacterSkills;
			base.IsReady = true;
		}

		// Token: 0x0600095C RID: 2396 RVA: 0x00038770 File Offset: 0x00036970
		public override void Deserialize(MBObjectManager objectManager, XmlNode node)
		{
			base.Deserialize(objectManager, node);
			XmlNode xmlNode = node.Attributes["occupation"];
			if (xmlNode != null)
			{
				this._occupation = (Occupation)Enum.Parse(typeof(Occupation), xmlNode.InnerText);
			}
			XmlNode xmlNode2 = node.Attributes["is_template"];
			this.IsTemplate = (xmlNode2 != null && Convert.ToBoolean(xmlNode2.InnerText));
			XmlNode xmlNode3 = node.Attributes["is_child_template"];
			this.IsChildTemplate = (xmlNode3 != null && Convert.ToBoolean(xmlNode3.InnerText));
			XmlNode xmlNode4 = node.Attributes["is_hidden_encyclopedia"];
			this.HiddenInEncylopedia = (xmlNode4 != null && Convert.ToBoolean(xmlNode4.InnerText));
			List<CharacterObject> list = new List<CharacterObject>();
			foreach (object obj in node.ChildNodes)
			{
				XmlNode xmlNode5 = (XmlNode)obj;
				if (xmlNode5.Name == "Traits")
				{
					this._characterTraits.Deserialize(objectManager, xmlNode5);
				}
				else if (xmlNode5.Name == "upgrade_targets")
				{
					foreach (object obj2 in xmlNode5.ChildNodes)
					{
						XmlNode xmlNode6 = (XmlNode)obj2;
						if (xmlNode6.Name == "upgrade_target")
						{
							CharacterObject item = objectManager.ReadObjectReferenceFromXml("id", typeof(CharacterObject), xmlNode6) as CharacterObject;
							list.Add(item);
						}
					}
				}
			}
			this.UpgradeTargets = list.ToArray();
			XmlNode xmlNode7 = node.Attributes["voice"];
			if (xmlNode7 != null)
			{
				this._persona = MBObjectManager.Instance.GetObject<TraitObject>(xmlNode7.Value);
			}
			XmlNode xmlNode8 = node.Attributes["is_basic_troop"];
			if (xmlNode8 != null)
			{
				this.IsBasicTroop = Convert.ToBoolean(xmlNode8.InnerText);
			}
			else
			{
				this.IsBasicTroop = false;
			}
			this.UpgradeRequiresItemFromCategory = objectManager.ReadObjectReferenceFromXml<ItemCategory>("upgrade_requires", node);
			XmlNode xmlNode9 = node.Attributes["level"];
			this.Level = ((xmlNode9 != null) ? Convert.ToInt32(xmlNode9.InnerText) : 1);
			if (node.Attributes["civilianTemplate"] != null)
			{
				this._civilianEquipmentTemplate = (objectManager.ReadObjectReferenceFromXml("civilianTemplate", typeof(CharacterObject), node) as CharacterObject);
			}
			if (node.Attributes["battleTemplate"] != null)
			{
				this._battleEquipmentTemplate = (objectManager.ReadObjectReferenceFromXml("battleTemplate", typeof(CharacterObject), node) as CharacterObject);
			}
			this._originCharacter = null;
		}

		// Token: 0x0600095D RID: 2397 RVA: 0x00038A60 File Offset: 0x00036C60
		public override float GetPower()
		{
			return CharacterObject.GetPowerImp(this.IsHero ? (this.HeroObject.Level / 4 + 1) : this.Tier, this.IsHero, this.IsMounted);
		}

		// Token: 0x0600095E RID: 2398 RVA: 0x00038A92 File Offset: 0x00036C92
		public override float GetBattlePower()
		{
			return MathF.Max(1f + 0.5f * (this.GetPower() - CharacterObject.GetPowerImp(0, false, false)), 1f);
		}

		// Token: 0x0600095F RID: 2399 RVA: 0x00038ABC File Offset: 0x00036CBC
		public override float GetMoraleResistance()
		{
			int num = this.IsHero ? (this.HeroObject.Level / 4 + 1) : this.Tier;
			return (this.IsHero ? 1.5f : 1f) * (0.5f * (float)num + 1f);
		}

		// Token: 0x06000960 RID: 2400 RVA: 0x00038B0C File Offset: 0x00036D0C
		public void GetSimulationAttackPower(out float attackPoints, out float defencePoints, Equipment equipment = null)
		{
			if (equipment == null)
			{
				equipment = this.Equipment;
			}
			attackPoints = 0f;
			defencePoints = 0f;
			float num = 0f;
			float num2 = 0f;
			float num3 = equipment.GetArmArmorSum() + equipment.GetHeadArmorSum() + equipment.GetHumanBodyArmorSum() + equipment.GetLegArmorSum();
			num3 = num3 * num3 / equipment.GetTotalWeightOfArmor(true);
			defencePoints += num3 * 10f + 4000f;
			for (EquipmentIndex equipmentIndex = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex < EquipmentIndex.NumAllWeaponSlots; equipmentIndex++)
			{
				EquipmentElement equipmentElement = equipment[equipmentIndex];
				if (!equipmentElement.IsEmpty)
				{
					float num4 = (equipmentElement.Item.RelevantSkill == null) ? 1f : (0.3f + (float)this.GetSkillValue(equipmentElement.Item.RelevantSkill) / 300f * 0.7f);
					float num5 = num4 * equipmentElement.Item.Effectiveness;
					if (equipmentElement.Item.PrimaryWeapon.IsRangedWeapon)
					{
						for (EquipmentIndex equipmentIndex2 = EquipmentIndex.WeaponItemBeginSlot; equipmentIndex2 < EquipmentIndex.NumAllWeaponSlots; equipmentIndex2++)
						{
							EquipmentElement equipmentElement2 = equipment[equipmentIndex];
							if (equipmentIndex != equipmentIndex2 && !equipmentElement2.IsEmpty && equipmentElement2.Item.PrimaryWeapon.IsAmmo)
							{
								num5 += num4 * equipmentElement2.Item.Effectiveness;
								break;
							}
						}
					}
					if (equipmentElement.Item.PrimaryWeapon.IsShield)
					{
						defencePoints += num5 * 10f;
					}
					else
					{
						num = MathF.Max(num, num5);
					}
				}
			}
			attackPoints += num;
			for (EquipmentIndex equipmentIndex3 = EquipmentIndex.ArmorItemEndSlot; equipmentIndex3 <= EquipmentIndex.HorseHarness; equipmentIndex3++)
			{
				EquipmentElement equipmentElement3 = equipment[equipmentIndex3];
				if (!equipmentElement3.IsEmpty)
				{
					num2 += equipmentElement3.Item.Effectiveness;
				}
			}
			float num6 = (equipment.Horse.Item == null || equipment.Horse.Item.RelevantSkill == null) ? 1f : (0.3f + (float)this.GetSkillValue(equipment.Horse.Item.RelevantSkill) / 300f * 0.7f);
			num2 *= num6;
			attackPoints += num2 * 2.5f;
			defencePoints += num2 * 5f;
		}

		// Token: 0x170001E7 RID: 487
		// (get) Token: 0x06000961 RID: 2401 RVA: 0x00038D3C File Offset: 0x00036F3C
		public override bool IsMounted
		{
			get
			{
				if (this.IsHero)
				{
					return this.Equipment[10].Item != null;
				}
				return base.IsMounted;
			}
		}

		// Token: 0x170001E8 RID: 488
		// (get) Token: 0x06000962 RID: 2402 RVA: 0x00038D70 File Offset: 0x00036F70
		public override bool IsRanged
		{
			get
			{
				if (this.IsHero)
				{
					for (int i = 0; i < 4; i++)
					{
						ItemObject item = this.Equipment[i].Item;
						if (item != null && (item.ItemType == ItemObject.ItemTypeEnum.Bow || item.ItemType == ItemObject.ItemTypeEnum.Crossbow))
						{
							return true;
						}
					}
				}
				return base.IsRanged;
			}
		}

		// Token: 0x06000963 RID: 2403 RVA: 0x00038DC4 File Offset: 0x00036FC4
		public float GetHeadArmorSum(bool civilianEquipment = false)
		{
			if (!civilianEquipment)
			{
				return this.FirstBattleEquipment.GetHeadArmorSum();
			}
			return this.FirstCivilianEquipment.GetHeadArmorSum();
		}

		// Token: 0x06000964 RID: 2404 RVA: 0x00038DE0 File Offset: 0x00036FE0
		public float GetBodyArmorSum(bool civilianEquipment = false)
		{
			if (!civilianEquipment)
			{
				return this.FirstBattleEquipment.GetHumanBodyArmorSum();
			}
			return this.FirstCivilianEquipment.GetHumanBodyArmorSum();
		}

		// Token: 0x06000965 RID: 2405 RVA: 0x00038DFC File Offset: 0x00036FFC
		public float GetLegArmorSum(bool civilianEquipment = false)
		{
			if (!civilianEquipment)
			{
				return this.FirstBattleEquipment.GetLegArmorSum();
			}
			return this.FirstCivilianEquipment.GetLegArmorSum();
		}

		// Token: 0x06000966 RID: 2406 RVA: 0x00038E18 File Offset: 0x00037018
		public float GetArmArmorSum(bool civilianEquipment = false)
		{
			if (!civilianEquipment)
			{
				return this.FirstBattleEquipment.GetArmArmorSum();
			}
			return this.FirstCivilianEquipment.GetArmArmorSum();
		}

		// Token: 0x06000967 RID: 2407 RVA: 0x00038E34 File Offset: 0x00037034
		public float GetHorseArmorSum(bool civilianEquipment = false)
		{
			if (!civilianEquipment)
			{
				return this.FirstBattleEquipment.GetHorseArmorSum();
			}
			return this.FirstCivilianEquipment.GetHorseArmorSum();
		}

		// Token: 0x06000968 RID: 2408 RVA: 0x00038E50 File Offset: 0x00037050
		public float GetTotalArmorSum(bool civilianEquipment = false)
		{
			return this.GetHeadArmorSum(civilianEquipment) + this.GetBodyArmorSum(civilianEquipment) + this.GetLegArmorSum(civilianEquipment) + this.GetArmArmorSum(civilianEquipment);
		}

		// Token: 0x06000969 RID: 2409 RVA: 0x00038E74 File Offset: 0x00037074
		public override BodyProperties GetBodyProperties(Equipment equipment, int seed = -1)
		{
			if (this.IsHero)
			{
				return this.HeroObject.BodyProperties;
			}
			if (seed == -2)
			{
				return this.GetBodyPropertiesMin(false);
			}
			if (seed == -1)
			{
				seed = base.StringId.GetDeterministicHashCode();
			}
			return FaceGen.GetRandomBodyProperties(base.Race, this.IsFemale, this.GetBodyPropertiesMin(false), this.GetBodyPropertiesMax(), (int)((equipment != null) ? equipment.HairCoverType : ArmorComponent.HairCoverTypes.None), seed, this.HairTags, this.BeardTags, this.TattooTags);
		}

		// Token: 0x170001E9 RID: 489
		// (get) Token: 0x0600096A RID: 2410 RVA: 0x00038EF0 File Offset: 0x000370F0
		public int TroopWage
		{
			get
			{
				if (this.IsHero)
				{
					return 2 + this.Level * 2;
				}
				return Campaign.Current.Models.PartyWageModel.GetCharacterWage(this);
			}
		}

		// Token: 0x0600096B RID: 2411 RVA: 0x00038F1A File Offset: 0x0003711A
		public void SetTransferableInPartyScreen(bool isTransferable)
		{
			if (isTransferable)
			{
				this._characterRestrictionFlags &= ~CharacterRestrictionFlags.NotTransferableInPartyScreen;
				return;
			}
			this._characterRestrictionFlags |= CharacterRestrictionFlags.NotTransferableInPartyScreen;
		}

		// Token: 0x0600096C RID: 2412 RVA: 0x00038F3D File Offset: 0x0003713D
		public void SetTransferableInHideouts(bool isTransferable)
		{
			if (isTransferable)
			{
				this._characterRestrictionFlags &= ~CharacterRestrictionFlags.CanNotGoInHideout;
				return;
			}
			this._characterRestrictionFlags |= CharacterRestrictionFlags.CanNotGoInHideout;
		}

		// Token: 0x170001EA RID: 490
		// (get) Token: 0x0600096D RID: 2413 RVA: 0x00038F60 File Offset: 0x00037160
		public int Tier
		{
			get
			{
				return Campaign.Current.Models.CharacterStatsModel.GetTier(this);
			}
		}

		// Token: 0x0600096E RID: 2414 RVA: 0x00038F77 File Offset: 0x00037177
		public void ClearAttributes()
		{
			if (this.IsHero)
			{
				this.HeroObject.ClearAttributes();
			}
		}

		// Token: 0x0600096F RID: 2415 RVA: 0x00038F8C File Offset: 0x0003718C
		public int GetTraitLevel(TraitObject trait)
		{
			if (this.IsHero)
			{
				return this.HeroObject.GetTraitLevel(trait);
			}
			return this._characterTraits.GetPropertyValue(trait);
		}

		// Token: 0x06000970 RID: 2416 RVA: 0x00038FAF File Offset: 0x000371AF
		public bool GetPerkValue(PerkObject perk)
		{
			return this.IsHero && this.HeroObject.GetPerkValue(perk);
		}

		// Token: 0x06000971 RID: 2417 RVA: 0x00038FC7 File Offset: 0x000371C7
		public override int GetSkillValue(SkillObject skill)
		{
			if (this.IsHero)
			{
				return this.HeroObject.GetSkillValue(skill);
			}
			return base.GetSkillValue(skill);
		}

		// Token: 0x06000972 RID: 2418 RVA: 0x00038FE5 File Offset: 0x000371E5
		public TraitObject GetPersona()
		{
			if (this._persona == null)
			{
				return DefaultTraits.PersonaSoftspoken;
			}
			return this._persona;
		}

		// Token: 0x06000973 RID: 2419 RVA: 0x00038FFB File Offset: 0x000371FB
		public override int GetMountKeySeed()
		{
			if (!this.IsHero)
			{
				return MBRandom.NondeterministicRandomInt;
			}
			return this.HeroObject.RandomValue;
		}

		// Token: 0x06000974 RID: 2420 RVA: 0x00039018 File Offset: 0x00037218
		public override FormationClass GetFormationClass()
		{
			if (!this.IsHero || this.Equipment == null)
			{
				return base.GetFormationClass();
			}
			ItemObject item = this.Equipment[EquipmentIndex.ArmorItemEndSlot].Item;
			bool flag = item != null && item.HasHorseComponent;
			bool flag2 = this.Equipment.HasWeaponOfClass(WeaponClass.Bow) || this.Equipment.HasWeaponOfClass(WeaponClass.Crossbow);
			if (!flag)
			{
				if (!flag2)
				{
					return FormationClass.Infantry;
				}
				return FormationClass.Ranged;
			}
			else
			{
				if (!flag2)
				{
					return FormationClass.Cavalry;
				}
				return FormationClass.HorseArcher;
			}
		}

		// Token: 0x06000975 RID: 2421 RVA: 0x0003908D File Offset: 0x0003728D
		public static CharacterObject Find(string idString)
		{
			return MBObjectManager.Instance.GetObject<CharacterObject>(idString);
		}

		// Token: 0x06000976 RID: 2422 RVA: 0x0003909C File Offset: 0x0003729C
		public static CharacterObject FindFirst(Predicate<CharacterObject> predicate)
		{
			return CharacterObject.All.FirstOrDefault((CharacterObject x) => predicate(x));
		}

		// Token: 0x06000977 RID: 2423 RVA: 0x000390CC File Offset: 0x000372CC
		public static IEnumerable<CharacterObject> FindAll(Predicate<CharacterObject> predicate)
		{
			return from x in CharacterObject.All
			where predicate(x)
			select x;
		}

		// Token: 0x170001EB RID: 491
		// (get) Token: 0x06000978 RID: 2424 RVA: 0x000390FC File Offset: 0x000372FC
		public static MBReadOnlyList<CharacterObject> All
		{
			get
			{
				return Campaign.Current.Characters;
			}
		}

		// Token: 0x06000979 RID: 2425 RVA: 0x00039108 File Offset: 0x00037308
		private static float GetPowerImp(int tier, bool isHero = false, bool isMounted = false)
		{
			return (float)((2 + tier) * (8 + tier)) * 0.02f * (isHero ? 1.5f : (isMounted ? 1.2f : 1f));
		}

		// Token: 0x040002B4 RID: 692
		private CharacterRestrictionFlags _characterRestrictionFlags;

		// Token: 0x040002B5 RID: 693
		[SaveableField(101)]
		private Hero _heroObject;

		// Token: 0x040002B6 RID: 694
		[SaveableField(103)]
		private CharacterObject _originCharacter;

		// Token: 0x040002B7 RID: 695
		private TraitObject _persona;

		// Token: 0x040002B8 RID: 696
		private CharacterTraits _characterTraits;

		// Token: 0x040002B9 RID: 697
		private CharacterObject _civilianEquipmentTemplate;

		// Token: 0x040002BA RID: 698
		private CharacterObject _battleEquipmentTemplate;

		// Token: 0x040002BE RID: 702
		private Occupation _occupation;
	}
}
